//
//  LSTestWrongQuesViewController.m
//  听说弱点强化训练
//
//  Created by 盛超 on 2018/8/23.
//  Copyright © 2018年 盛超. All rights reserved.
//

#import "LSTestWrongQuesViewController.h"
#import "LSWrongQuesController.h"
#import "LSWrongQuesListManager.h"
#import "LSResFirstController.h"
#import "DicMainView.h"
#import "LSWrongBookController.h"

@interface LSTestWrongQuesViewController ()<DicMainViewDelegate>

@property (nonatomic,strong) LSModelWrongQuesList *model;

@end

@implementation LSTestWrongQuesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    [self addBYItemviews:@[@"LS-nav_back"] mode:ByNavigationItemModeImage position:ByNavigationItemPositionModeLeft];
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:@"LS-大背景"];
    [self.view addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.view);
    }];

    UIImageView *navImageView = [[UIImageView alloc] init];
    navImageView.image = [UIImage imageNamed:@"LS-content_nav"];
    [self.view addSubview:navImageView];
    [navImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.view);
        make.height.mas_equalTo(kNavgationBar);
    }];
    
    [self loadData];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self setNaviAttributeWithTranslucent:YES stateBarLightContent:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)loadData {
    
    LSWrongQuesListManager *manager = [[LSWrongQuesListManager alloc] init];
    NSDictionary *dict = @{@"StuID":DR_UserInfo.UserID,
                           @"SchoolID":KGetUserDefaults(@"SchoolID"),
                           @"StageNo":KGetUserDefaults(@"TestLayer"),
                           @"TypeID":@"-1"
                           };
    manager.requestParam = @{@"DictString":[NSObject objectToJson:dict]};
    [manager requestWithCompltionSuccess:^(LSModelWrongQuesList *model) {
        self.model = model;
        
        NSString *ftpServerAddress = _model.FtpServerAddress;
        NSString *ftpUserPwd = _model.sUserPwd;
        NSString *ftpUser = _model.sUserName;
        [ZBFtpTools ZBFtp_setupInitWithHost:ftpServerAddress
                                       user:ftpUser
                                        psw:ftpUserPwd];

        
        dispatch_async(dispatch_get_main_queue(), ^{
            UIButton *btn = [[UIButton alloc] init];
            btn.backgroundColor = [UIColor orangeColor];
            [btn setTitle:@"进入错题" forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(pushWrong) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:btn];
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.center.equalTo(self.view);
                make.size.mas_equalTo(CGSizeMake(100, 40));
            }];
            
            UIButton *btn2 = [[UIButton alloc] init];
            btn2.backgroundColor = [UIColor orangeColor];
            [btn2 setTitle:@"进入听力试题包" forState:UIControlStateNormal];
            [btn2 addTarget:self action:@selector(pushListen) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:btn2];
            [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(self.view);
                make.centerY.equalTo(self.view).offset(100);
                make.size.mas_equalTo(CGSizeMake(130, 40));
            }];
            
            UIButton *btn3 = [[UIButton alloc] init];
            btn3.backgroundColor = [UIColor orangeColor];
            [btn3 setTitle:@"进入朗读试题包" forState:UIControlStateNormal];
            [btn3 addTarget:self action:@selector(pushRead) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:btn3];
            [btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(self.view);
                make.centerY.equalTo(self.view).offset(200);
                make.size.mas_equalTo(CGSizeMake(130, 40));
            }];
            
            UIButton *btn4 = [[UIButton alloc] init];
            btn4.backgroundColor = [UIColor orangeColor];
            [btn4 setTitle:@"知识点课件" forState:UIControlStateNormal];
            [btn4 addTarget:self action:@selector(zsdKJ) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:btn4];
            [btn4 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(self.view);
                make.centerY.equalTo(self.view).offset(300);
                make.size.mas_equalTo(CGSizeMake(130, 40));
            }];
            
            UIButton *btn5 = [[UIButton alloc] init];
            btn5.backgroundColor = [UIColor orangeColor];
            [btn5 setTitle:@"错题本" forState:UIControlStateNormal];
            [btn5 addTarget:self action:@selector(pushWrongList) forControlEvents:UIControlEventTouchUpInside];
            [self.view addSubview:btn5];
            [btn5 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(self.view);
                make.centerY.equalTo(self.view).offset(-100);
                make.size.mas_equalTo(CGSizeMake(130, 40));
            }];

        });
        
    } failuer:^(NSString *error) {
        
    }];
    
}

- (void)pushWrongList {
    LSWrongBookController *vc = [[LSWrongBookController alloc] init];
    [self push:vc];
}

- (void)pushWrong {
    LSWrongQuesController *vc = [[LSWrongQuesController alloc] init];
    vc.model = self.model;
    [self push:vc];
}

- (void)pushListen {
    LSResFirstController *listen = [[LSResFirstController alloc] init];
    listen.TypeID = @"SE";
    [self push:listen];
}

- (void)pushRead {
    LSResFirstController *read = [[LSResFirstController alloc] init];
    read.TypeID = @"Spn";
    [self push:read];
}

#pragma mark - DicMainViewDelegate
- (void)colseDicMainView:(UIView *)dictView {
    [dictView removeFromSuperview];
    dictView = nil;
}

- (void)zsdKJ {
    
    dispatch_async(dispatch_get_main_queue(), ^{
        DicMainView *main = [[DicMainView alloc] initWithTestType:DictTestType_Word isShowRecord:YES];
        main.delegate = self;
        main.dictUrl = [NSString stringWithFormat:@"%@api/ZXYYTS/W_ZXYYTS_GetCoursewareByCode",KGetUserDefaults(@"SystemIP")];
        main.dictParam = @{@"knowledge":@"CC040151νAa26CCAA",
                           @"levelCode":@"B",
                           @"stageNo":KGetUserDefaults(@"TestLayer"),
                           @"schoolId":DR_UserInfo.SchoolID,
                           @"stuId":DR_UserInfo.UserID,
                           };
        [main popAnimated:YES];
    });

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
